package com.example.exchangeapp.zjs;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

public class Product implements Parcelable {
    private Integer id;             //商品id
    private String tUserId;         //发布商品的用户（卖家）id
    private long imageCode;      //一组图片的唯一标识
    private String content;         //商品描述信息（商品名称）
    private Double price;           //商品价格
    private String addr;            //卖家所在地
    private Integer typeId;         //商品类型id
    private String typeName;        //商品类型名称
    private String username;        //当前商品发布者用户名
    private String avatar;          //当前商品发布者头像
    private List<String> imageUrlList;  //图片的list集合

    public Integer getId() {
        return id;
    }

    public String getUserId() {
        return tUserId;
    }

    public long getImageCode() {
        return imageCode;
    }

    public String getContent() {
        return content;
    }

    public Double getPrice() {
        return price;
    }

    public String getAddr() {
        return addr;
    }

    public Integer getTypeId() {
        return typeId;
    }

    public String getTypeName() {
        return typeName;
    }

    public String getUsername() {
        return username;
    }

    public String getAvatar() {
        return avatar;
    }

    public List<String> getImageUrlList() {
        return imageUrlList;
    }


    // Parcelable接口的实现方法
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        // 将商品的字段写入Parcel对象
        dest.writeInt(id);
        dest.writeString(tUserId);
        dest.writeLong(imageCode);
        dest.writeString(content);
        dest.writeDouble(price);
        dest.writeString(addr);
        dest.writeInt(typeId);
        dest.writeString(typeName);
        dest.writeString(username);
        dest.writeString(avatar);
        dest.writeStringList(imageUrlList);
    }

    // 从Parcel对象中创建商品对象
    public static final Creator<Product> CREATOR = new Creator<Product>() {
        @Override
        public Product createFromParcel(Parcel in) {
            return new Product(in);
        }

        @Override
        public Product[] newArray(int size) {
            return new Product[size];
        }
    };

    protected Product(Parcel in) {
        // 从Parcel对象中读取商品字段并赋值给类的字段
        id = in.readInt();
        tUserId = in.readString();
        imageCode = in.readLong();
        content = in.readString();
        price = in.readDouble();
        addr = in.readString();
        typeId = in.readInt();
        typeName = in.readString();
        username = in.readString();
        avatar = in.readString();
        imageUrlList = in.createStringArrayList();
    }
}
